package com.jet.merchant.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jet.core.utils.IdUtil;
import com.jet.merchant.domain.dto.RoleResourceMapDto;
import com.jet.merchant.domain.entity.ClerkRoleResourceMap;
import com.jet.merchant.mapper.ClerkRoleResourceMapMapper;
import com.jet.merchant.service.IClerkRoleResourceMapService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-02-25
 */
@Service
public class ClerkRoleResourceMapServiceImpl extends ServiceImpl<ClerkRoleResourceMapMapper, ClerkRoleResourceMap> implements IClerkRoleResourceMapService {

    @Override
    public void save(RoleResourceMapDto dto) {
        ClerkRoleResourceMap entity = new ClerkRoleResourceMap();
        entity.setId(IdUtil.generateLower());
        entity.setResourceId(dto.getResourceId());
        entity.setRoleId(dto.getRoleId());
        super.save(entity);
    }

    @Override
    public void deleteByRoleId(String roleId) {
        Wrapper<ClerkRoleResourceMap> wrapper = new LambdaQueryWrapper<ClerkRoleResourceMap>()
                .eq(ClerkRoleResourceMap::getRoleId, roleId);
        super.remove(wrapper);
    }

    @Override
    public List<ClerkRoleResourceMap> findAllByRoleId(String roleId) {
        Wrapper<ClerkRoleResourceMap> wrapper = new LambdaQueryWrapper<ClerkRoleResourceMap>()
                .eq(ClerkRoleResourceMap::getRoleId, roleId);
        return super.list(wrapper);
    }
}
